# -*- coding: utf-8 -*-
"""
------------------------------------------------------------------------------
    File Name:  Incr_decs
    Author   :  wanwei1029
    Date     :  2018/10/12
    Desc     :
------------------------------------------------------------------------------
"""
import redis
import threading
import time
HOST = "192.168.99.100"
PORT = "6379"
DB = 0

INC_FLAG = "incFlag"


class IncrThread(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
        sr = redis.StrictRedis(host=HOST, port=PORT, db=DB)
        self.sr = sr

    def run(self):
        time.sleep(5)
        current_time = time.localtime()
        time_flag = time.strftime("%d:%H:", current_time)
        min = int(current_time.tm_min / 10)
        print(time_flag+str(min))
        print(min)
        # self.sr.incr(INC_FLAG+"_"+time_flag)


def demo():
    """
    incr和decr可以实现高并发下的递增或递减
    """
    thread_num = 1
    while thread_num:
        incr = IncrThread()
        incr.start()
        thread_num -= 1
    print("done!")


if __name__ == '__main__':
    test_method = "demo"
    if test_method == "demo":
        demo()
